# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
from apps.pms.models import Product, Module, Requirement
from apps.pms.module.widgets import ModuleForeignKeyWidget
from apps.sys.models import User


class RequirementResouces(CustomerModelResource):
    product = Field(attribute="product", widget=ForeignKeyWidget(Product, field="name"))
    module = Field(
        attribute="module", widget=ModuleForeignKeyWidget(Module, field="name")
    )
    owner = Field(attribute="owner", widget=ForeignKeyWidget(User, field="username"))

    class Meta:
        model = Requirement
        fields = (
            "name",
            "product",
            "module",
            "owner",
            "priority",
            "origin",
            "classify",
            "desc",
            "criteria",
            "remark",
        )
        import_id_fields = ("name", "product")
        export_order = fields
